import { BasicColumn, FormSchema } from '@/components/Table';
import { h, ref } from 'vue';
import { Tag } from 'ant-design-vue';
import {VxeFormItemProps, VxeGridPropTypes} from "@/components/VxeTable";
import util from "@/utils/util";
import { deptSelectList } from '@/api/sys/iot';


/**
 */
export const vxeTableColumns: VxeGridPropTypes.Columns = [
  {
    title: 'id',
    field: 'id',
    showOverflow: 'title',
    align: 'center',
    width: 50,
  },
  {
    title: '来源',
    field: 'source',
    align: 'center',
    width: 150,
  },
  {
    title: 'txt',
    field: 'txt',
    showOverflow: 'title',
    // width: 130,
    align: 'center',
  },
  {
    title: 'locationIds',
    field: 'locationIds',
    align: 'center',
    width: 150,
  },
  {
    title: '是否测试',
    field: 'izTest',
    align: 'center',
    width: 100,
  },
  // {
  //   title: '发送标签mac',
  //   field: 'bianQianDengRequest',
  //   align: 'center',
  // },
  // {
  //   title: '响应mac',
  //   field: 'bianQianDengRespone',
  //   align: 'center',
  // },
  {
    title: '创建时间',
    field: 'createTime',
    width: 130,
    align: 'center',
  },

  {
    width: 60,
    title: '操作',
    align: 'center',
    field: '',
    slots: { default: 'action' },
    fixed: 'right',
  },
];



export const itemColumns: VxeGridPropTypes.Columns = [
  {
    title: '序号',
    type: 'seq',
    fixed: 'left',
    width: '50',
    align: 'center',
  },
  {
    title: '订单标识号',
    field: 'childOrderNo',
    showOverflow: 'title',
    align: 'center',
    width: 90,
  },
  {
    title: '操作人',
    field: 'creator',
    showOverflow: 'title',
    width: 100,
    align: 'center',
  },
  {
    title: '库位id',
    field: 'houseLocationOID',
    align: 'center',
    width: 50,
  },
  {
    title: '库位名称',
    field: 'houseLocationName',
    filters: [{ data: '' }],
    filterRender: {
      name: 'VxeInput',
    },
    align: 'center',
    width: 130,
  },
  {
    title: '物料编号',
    field: 'materialTID',
    align: 'center',
    width: 200,
  },
  {
    title: '物料名称',
    field: 'materialName',
    align: 'center',
    width: 100,
  },
  {
    title: '标签mac',
    field: 'tagMac',
    align: 'center',
    filters: [{ data: '' }],
    filterRender: {
      name: 'VxeInput',
    },
    width: 100,
  },
  {
    title: '标签状态',
    field: 'status',
    align: 'center',
    width: 100,
    slots:{
      default: ({ row }) => {
        const type = row.status;
        let text = '';
        let color="";
        switch (type) {
          case 1:
            text = '亮灯';
            color="green";
            break;
          case 0:
            color="red";
            text = '灭灯';
            break;
        }
        // return text;
        return h(Tag, {color}, () => text);
      },
    }
  },
  {
    title: '创建时间',
    field: 'operatingTime',
    width: 130,
    align: 'center',
  },

  // {
  //   width: 120,
  //   title: '操作',
  //   align: 'center',
  //   field: '',
  //   slots: { default: 'action' },
  //   fixed: 'right',
  // },
];
export const itemColumns2: VxeGridPropTypes.Columns = [
  {
    title: '来源',
    field: 'source',
    showOverflow: 'title',
    align: 'center',
    width: 90,
  },
  {
    title: '库区',
    field: 'type',
    showOverflow: 'title',
    width: 100,
    align: 'center',
  },
  {
    title: '发送标签',
    field: 'requestSend',
    align: 'center',
    filters: [{ data: '' }],
    filterRender: {
      name: 'VxeInput',
    },
  },
  {
    title: '是否测试',
    field: 'izTest',
    align: 'center',
    width: 80,
  },
  {
    title: '开启状态',
    field: 'status',
    align: 'center',
    width: 80,
    slots:{
      default: ({ row }) => {
        const type = row.status;
        let text = '';
        let color="";
        switch (type) {
          case 1:
            text = '亮灯';
            color="green";
            break;
          case 0:
            color="red";
            text = '灭灯';
            break;
        }
        // return text;
        return h(Tag, {color}, () => text);
      },
    }
  },
  {
    title: '开启时间',
    field: 'startTime',
    width: 130,
    align: 'center',
  },
  {
    title: '关闭时间',
    field: 'endTime',
    width: 130,
    align: 'center',
  },
  // {
  //   width: 120,
  //   title: '操作',
  //   align: 'center',
  //   field: '',
  //   slots: { default: 'action' },
  //   fixed: 'right',
  // },
];


export const vxeTableFormSchema: VxeFormItemProps[] = [
  {
    span: 5,
    field: 'keyword',
    title: '搜索',
    itemRender: {
      props: {
        placeholder: '搜索',
      },
      name: 'AInput',
    },
  },

  {
    span: 5,
    itemRender: {
      name: 'VxeButtonGroup',
      options: [
        { type: 'reset', content: '重置' },
        { type: 'submit', content: '查询', status: 'primary' },
      ],
    },
  },
];


export const formSchema: FormSchema[] = [

  {
    field: 'shelfName',
    label: '架子名称',
    component:"Input",
    required: true,
  },
  {
    field: 'deptId',
    label: '部门',
    component:"ApiSelect",
    componentProps: {
      api: deptSelectList,
      // mode:"multiple",
      resultField:"data",
      labelField: 'deptName',
      valueField: 'deptId',
    },
    required: false,
  },

  {
    field: 'tagNo',
    label: '巷道灯编号',
    component:"Input",
    required: false,
  },
  {
    field: 'sort',
    label: '排序',
    component:"InputNumber",
    required: false,
  },

];
